﻿using System;
using System.Globalization;
using System.Collections.Generic;

using SBPweb.Modules.Modularity;

using SBPweb.MediaCenter.Common.Services;

namespace SBPweb.MediaCenter.Common.Modularity
{

    public abstract class ModuleBase : SBPweb.Modules.Modularity.ModuleBase
    {

        #region Constructor logic

        public ModuleBase(SBPweb.Modules.Modularity.IModuleHost parent)
            : base(parent)
        {
            InstantiateServices();
        }

        #endregion

        #region Property accessors

        public ILayoutService LayoutService
        {
            get
            {
                return pHost.ModuleLoader.Services.Get<ILayoutService>();
            }
        }

        #endregion

        #region Methods

        public override void Initialize()
        {
            if (LayoutService != null)
            {
                LayoutService.Initializing += new EventHandler(OnLayoutServiceInitializing);
                LayoutService.Initialized += new EventHandler(OnLayoutServiceInitialized);
            }
        }

        public abstract void InitializeMenus();

        public abstract void InitializeSmartparts();

        public virtual void InstantiateServices()
        {
        }

        #endregion

        #region Event handlers

        protected virtual void OnLayoutServiceInitializing(object sender, EventArgs e)
        {
            InitializeSmartparts();
            InitializeMenus();
        }

        protected virtual void OnLayoutServiceInitialized(object sender, EventArgs e)
        {
        }

        #endregion

    }

}